package com.rainy.generator.common.util;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @author liuqin on 2017/12/16
 */
public class ResultUtil {

    public  static <T> Map<String,Object> toJsonSuccResult(T data){
        return toJsonResult(data, 0, "成功!",null);
    }

    public  static <T> Map<String,Object> toJsonResult(T data,long count){
        return toJsonResult(data, 0, "成功!",count);
    }

    public  static <T> Map<String,Object> toJsonResult(T data,int code,String msg){
       return toJsonResult(data, code, msg,null);
    }

    private  static <T> Map<String,Object> toJsonResult(T data,int code,String msg,Long count){
        Map<String,Object> map = Maps.newHashMap();
        map.put("code",code);
        map.put("msg",msg);
        map.put("data",data);
        if (count!=null){
            map.put("count",count);
        }
        return map;
    }
}
